package com.woniu.service.impl;

import com.woniu.entity.Major1;
import com.woniu.mapper.MajorDao;
import com.woniu.pojo.Major;
import com.woniu.pojo.MajorExample;
import com.woniu.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class MajorServiceImpl implements MajorService {
    @Autowired
    MajorDao majorDao;

    @Override
    public void add(Major major) {
        majorDao.insert(major);
    }

    @Override
    public void deleteById(Integer id) {
        majorDao.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteByIds(Integer[] ids) {
        for (Integer id:ids) {
            majorDao.deleteByPrimaryKey(id);
        }
    }

    @Override
    public Major findOne(Integer id) {
        Major major = majorDao.selectByPrimaryKey(id);
        return major;
    }

    @Override
    public void updateById(Major major) {
        majorDao.updateByPrimaryKeySelective(major);
    }

    @Override
    public List<Major> selectByExample(Major major) {
        MajorExample majorExample = new MajorExample();
        majorExample.createCriteria().andMajorNameEqualTo(major.getMajorName());
        List<Major> majorList = majorDao.selectByExample(majorExample);
        return majorList;
    }

    @Override
    public Major1 findOne1(Integer id) {
        return majorDao.selectByPrimaryKey1(id);
    }

    @Override
    public List<Major1> selectByExample1(Major major) {
        MajorExample majorExample=new MajorExample();
        MajorExample.Criteria criteria = majorExample.createCriteria();
        if (major.getDeptId()!=null&&major.getDeptId()!=0){
            criteria.andDeptIdEqualTo(major.getDeptId());
        }
        if(major.getMajorName()!=null&&!major.getMajorName().equals("")){
            criteria.andMajorNameLike("%"+major.getMajorName()+"%");
        }
        return majorDao.selectByExample1(majorExample);
    }
}
